<template>
  <router-view />
  <van-overlay :show="showOverlay" z-index="99">
    <div class="overlayLoad">
    <van-loading type="spinner"/>

    </div>
  </van-overlay>
</template>

<script>
import { defineComponent, onMounted, ref, watch } from "vue";
import { post } from "./untils/request/index";
import store from "./store";

export default defineComponent({
  setup() {
    const showOverlay = ref(store.state.showOverlay);
    // 打包APP自动更新
    function getver(arg) {
      post("/portal", {
        module: "Utils",
        interface: "1002",
        data: {
          platform: 1,
          version: arg,
        },
      })
        .then((res) => {
          if (res.data.needUpgrade) {
            window.test.version(JSON.stringify(res.data.newVersion));
          } else {
            return;
          }
        })
        .catch((err) => {
          console.log("检测更新失败", err);
        });
    }

    watch(
      () => store.state.showOverlay,
      (newValue) => {
        showOverlay.value = newValue;
      },
      { deep: true }
    );

    onMounted(() => {
      window.changeversion = (...arg) => getver(...arg);
    });
    return {
      showOverlay,
      getver,
    };
  },
});
</script>

<style lang="less">
#app {
  font-family: PingFangSC-Regular, PingFang SC;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #000000;
  font-size: 16px;
  min-height: 100vh;
  background-color: #ffffff;
}
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
a {
  text-decoration: none;
}
li {
  list-style: none;
}
.overlayLoad {
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}
</style>
